/**
 *
 */
import Util;
import OpenApi;

import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    cn-qingdao = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-beijing = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-chengdu = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-zhangjiakou = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-huhehaote = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-hangzhou = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-shanghai = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-shenzhen = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-heyuan = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-wulanchabu = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-hongkong = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-2 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-3 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-5 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    eu-west-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    us-west-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    us-east-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    eu-central-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    me-east-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-south-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    cn-shanghai-finance-1 = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-shenzhen-finance-1 = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-north-2-gov-1 = 'wafopenapi.cn-hangzhou.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('waf-openapi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

